import request from "@/utils/request";
import { SpecGroupPageVO } from "@/api/spec/group/spec-group.ts";

const SPECVALUE_BASE_URL = "/api/v1/spec-value";

const SpecValueAPI = {
  /** 获取规格值分页数据 */
  getPage(queryParams?: SpecValuePageQuery) {
    return request<any, PageResult<SpecValuePageVO[]>>({
      url: `${SPECVALUE_BASE_URL}/page`,
      method: "get",
      params: queryParams,
    });
  },
  /**
   * 获取规格值表单数据
   *
   * @param id 规格值ID
   * @returns 规格值表单数据
   */
  getFormData(id: number) {
    return request<any, SpecValueForm>({
      url: `${SPECVALUE_BASE_URL}/${id}/form`,
      method: "get",
    });
  },

  /**
   *  添加规格值
   *
   *  @param data 规格值表单数据
   */
  add(data: SpecValueForm) {
    return request({
      url: `${SPECVALUE_BASE_URL}`,
      method: "post",
      data: data,
    });
  },

  /**
   * 更新规格值
   *
   * @param id 规格值ID
   * @param data 规格值表单数据
   */
  update(id: number, data: SpecValueForm) {
    return request({
      url: `${SPECVALUE_BASE_URL}/${id}`,
      method: "put",
      data: data,
    });
  },

  /**
   * 批量删除规格值，多个以英文逗号(,)分割
   *
   * @param ids 规格值ID字符串，多个以英文逗号(,)分割
   */
  deleteByIds(ids: string) {
    return request({
      url: `${SPECVALUE_BASE_URL}/${ids}`,
      method: "delete",
    });
  },

  getSpecGroupList(queryParams?: SpecValuePageQuery) {
    return request<any, ResponseData<SpecGroupPageVO[]>>({
      url: `${SPECVALUE_BASE_URL}/getSpecGroupList`,
      method: "get",
      params: queryParams,
    });
  },
};

export default SpecValueAPI;

/** 规格值分页查询参数 */
export interface SpecValuePageQuery extends PageQuery {
  categoryId?: number;
  /** 所属规格组ID */
  specGroupId?: number;
  /** 规格值名称(如:红色/S码) */
  valueName?: string;
  createTime?: [string, string];
  groupName?: string;
}

/** 规格值表单对象 */
export interface SpecValueForm {
  /** 规格值ID */
  id?: number;
  /** 所属规格组ID */
  specGroupId?: number;
  /** 规格值名称(如:红色/S码) */
  valueName?: string;
}

/** 规格值分页对象 */
export interface SpecValuePageVO {
  /** 规格值ID */
  id?: number;
  /** 所属规格组ID */
  specGroupId?: number;
  /** 规格值名称(如:红色/S码) */
  valueName?: string;
  createTime?: Date;
  categoryId?: number;
}
